package com.qc.bug.Controller;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.qc.bug.Services.userInfoServices;
import com.qc.bug.Util.User;
import com.qc.bug.Util.sendEmailUtil;
import com.qc.bug.pojo.UserInfo;

@Controller
@RequestMapping(value="/sendEmailContr")
public class sendEmailController {

	@Autowired
	private userInfoServices userInfoBiz;
	/**
	 * 发送邮件信息
	 * @param session
	 * @param forEmail
	 * @param map
	 * @return
	 */
	@RequestMapping(value="/sendEmail")
	public String senEmail(@RequestParam String forEmail,HttpSession session,Map<String,Object> map){
		sendEmailUtil.sendEmail(forEmail);
		session.setAttribute("mailbox", forEmail);
		map.put("result", "验证信息已发送到您的邮箱！");
		return "result/result";
	}
	
	@RequestMapping(value="/updateEmail")
	public String updateEmail(HttpSession session,Map<String,Object> map){
		String mailbox=(String) session.getAttribute("mailbox");
		UserInfo userinfo=(UserInfo) session.getAttribute(User.USER_INFO);
		userinfo.setMailbox(mailbox);
		userInfoBiz.updateUserMail(userinfo);
		
		map.put("result", "验证成功");
		return "result/result";
	}
}
